#include "main/utils.h"
using namespace std;

class Solution {
public:
    vector<vector<char>> rotateTheBox(vector<vector<char>>& box) {
      int row = box.size();
      int col = box[0].size();
      for (int i = 0; i < row; ++i) {
        int last_empty_pos = -1;
        for (int j = col - 1; j >= 0; --j) {
          if (box[i][j] == '.') {
            if (last_empty_pos == -1) {
              last_empty_pos = j;
            }
          } else if (box[i][j] == '*') {
            last_empty_pos = -1;
          } else if (box[i][j] == '#') {
            if (last_empty_pos > j) {
              box[i][last_empty_pos] = '#';
              box[i][j] = '.';
              --last_empty_pos;
            }
          } else {
            cout << "invalid input" << endl;
          }
        }
      }
      vector<vector<char>> new_box(col, vector<char>(row));
      for (int i = 0; i < row; ++i) {
        for (int j = 0; j < col; ++j) {
          new_box[j][row - i - 1] = box[i][j];
        }
      }
      return new_box;
    }
};

int main() {
  vector<vector<char>> box = {{'#', '.', '*', '.'}, {'#', '#', '*', '.'}};
  Solution su;
  auto new_box = su.rotateTheBox(box);
  printVec("leetcode1861", new_box);

  return 0;
}
